package com.xuchaotong.service.impl;

import com.xuchaotong.entity.Order;
import com.xuchaotong.entity.User;
import com.xuchaotong.service.OrderService;
import com.xuchaotong.service.PropagationDemoService;
import com.xuchaotong.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Component
public class PropagationDemoServiceImpl implements PropagationDemoService{

    @Autowired
    private UserService userService;

    @Autowired
    private OrderService orderService;

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void saveUserAndOrder() {
        User user = new User();
        user.setName("Jenny");
        userService.saveUser(user);


        Order order = new Order();
        order.setOrderNo("NO1122200");
        orderService.saveOrder(order);

        throw new RuntimeException();
    }
}
